package com.grt.condify.common;

import com.grt.condify.utils.StringUtil;

import java.io.Serializable;


/**
 * 结果报告类 ，该类为程序中需要生成结果信息提供了支持
 * 报告分为题目和正文，题目通过字符串定义报告的名称，正文内容可以是任意类型。
 * 一般我们不会直接使用这个类，而是通过其工具类Reports来进行报告的生成工作
 * Created by cy on 2015/11/25.
 */
public class Report<C> implements Serializable {

    private String title;
    private C detail;
    private RESULT result;

    /**
     * 报告携带的上下文
     */
    private Object context;

    /**
     * 结果类型
     */
    public static enum RESULT {
        SUCCESS, FAIL, UNKNOW
    }

    public Report(String title) {
        this(title, null);
    }

    public Report(String title, C detail) {
        this(title, detail, RESULT.SUCCESS);
    }

    public Report(String title, C detail, RESULT result) {
        this(title, detail, result, null);
    }

    public Report(String title, C detail, RESULT result, Object context) {
        this.title = StringUtil.showEmpty(title);
        this.detail = detail;
        this.result = result == null ? RESULT.SUCCESS : result;
        this.context = context;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public C getDetail() {
        return detail;
    }

    public void setDetail(C detail) {
        this.detail = detail;
    }

    public RESULT getResult() {
        return result;
    }

    public void setResult(RESULT result) {
        if (result != null) {
            this.result = result;
        }
    }

    public Object getContext() {
        return context;
    }

    public void setContext(Object context) {
        this.context = context;
    }

    /**
     * 重写toString方法，生成报告类对应的报告细节
     * 该方法只返回报告的细节内容，如果细节对象是字符串，直接返回内容
     * 如果细节内容为对象，则遍历对象的
     *
     * @return
     */
    @Override
    public String toString() {
        return super.toString();
    }
}
